﻿using System;
using System.Windows.Forms;

public class TextBoxFind
{
    string _Value = "Từ khóa";
    TextBox _TextBox;
    ToolStripTextBox _ToolStripTextBox;
    public TextBoxFind(TextBox textBox, string value)
    {
        if (value.Length > 0)
            _Value = value;

        _TextBox = textBox;
        _TextBox.Text = _Value;
        _TextBox.ForeColor = System.Drawing.Color.Silver;
        _TextBox.Enter += new EventHandler(TextBox_Enter);
        _TextBox.Leave += new EventHandler(TextBox_Leave);
        _TextBox.TextChanged += new EventHandler(TextBox_TextChanged);

    }
    void TextBox_TextChanged(object sender, EventArgs e)
    {
        TextBox t = (TextBox)sender;
        if (t.Text == "" || t.Text == _Value)
        {
            t.ForeColor = System.Drawing.Color.Silver;
        }
        else
        {
            t.ForeColor = System.Drawing.SystemColors.WindowText;
        }
    }

    void TextBox_Leave(object sender, EventArgs e)
    {
        TextBox t = (TextBox)sender;
        if (t.Text == "" || t.Text == _Value)
        {
            t.ForeColor = System.Drawing.Color.Silver;
            t.Text = _Value;
        }
        else
        {
            t.ForeColor = System.Drawing.SystemColors.WindowText;
        }
    }

    void TextBox_Enter(object sender, EventArgs e)
    {
        TextBox t = (TextBox)sender;
        if (t.Text == _Value)
        {
            t.ForeColor = System.Drawing.SystemColors.WindowText;
            t.Text = "";
        }
    }


    public TextBoxFind(ToolStripTextBox textBox, string value)
    {
        if (value.Length > 0)
            _Value = value;

        this._ToolStripTextBox = textBox;
        this._ToolStripTextBox.Text = _Value;
        this._ToolStripTextBox.ForeColor = System.Drawing.Color.Silver;

        this._ToolStripTextBox.Enter += new EventHandler(ToolStripTextBox_Enter);
        this._ToolStripTextBox.Leave += new EventHandler(ToolStripTextBox_Leave);
        this._ToolStripTextBox.TextChanged += new EventHandler(ToolStripTextBox_TextChanged);
    }

    void ToolStripTextBox_TextChanged(object sender, EventArgs e)
    {
        ToolStripTextBox t = (ToolStripTextBox)sender;
        if (t.Text == "" || t.Text == _Value)
        {
            t.ForeColor = System.Drawing.Color.Silver;
        }
        else
        {
            t.ForeColor = System.Drawing.SystemColors.WindowText;
        }
    }

    void ToolStripTextBox_Leave(object sender, EventArgs e)
    {
        ToolStripTextBox t = (ToolStripTextBox)sender;
        if (t.Text == "" || t.Text == _Value)
        {
            t.ForeColor = System.Drawing.Color.Silver;
            t.Text = _Value;
        }
        else
        {
            t.ForeColor = System.Drawing.SystemColors.WindowText;
        }
    }

    void ToolStripTextBox_Enter(object sender, EventArgs e)
    {
        ToolStripTextBox t = (ToolStripTextBox)sender;
        if (t.Text == _Value)
        {
            t.ForeColor = System.Drawing.SystemColors.WindowText;
            t.Text = "";
        }
    }

}